package movee.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.File;

/**
 *
 *
 * @author movee
 */
@Slf4j
public final class FileUtils {

    private FileUtils() {}

    public static boolean createDirecotryIfNotExist(String dir) {
        File file = new File(dir);
        if (!file.exists()) {
            boolean success = file.mkdirs();
            if (success) {
                boolean psuccess = file.setReadable(true, false);
                if (!psuccess) {
                    log.warn("set readable permission failed. dir: {}", dir);
                }
                psuccess = file.setWritable(true, false);
                if (!psuccess) {
                    log.warn("set writable permission failed. dir: {}", dir);
                }
                psuccess = file.setExecutable(true, false);
                if (!psuccess) {
                    log.warn("set executable permission failed. dir: {}", dir);
                }
            } else {
                log.warn("create directory failed. dir: {}", dir);
            }
            return success;
        }

        return true;
    }

}
